package utils.audit;

import models.common.AuditInfo;
import play.mvc.Scope;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * Created by sqw on 2017/4/23.
 */
public class AuditListener {

    @PrePersist
    public void setCreatedAt( AuditInfo entity) {
        entity.createUser = Scope.Session.current().get("username");
        entity.createDate = new Date();
    }
    @PreUpdate
    public void setUpdatedAt(AuditInfo entity){
        entity.lastUpdater = Scope.Session.current().get("username");
        entity.lastUpdateDate = new Date();
    }
}
